<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0"/>
    <title>用户中心</title>
    <link rel="stylesheet" href="../../css/amazeui.min.css">
    <link rel="stylesheet" href="css/app.css">
     <style>
    	 	
    	 	.clear{clear:both; margin-bottom:10px;}

			.content{padding: 10px;}
			.title{font-size: 16px; line-height: 20px;overflow: hidden; margin-bottom:13px;}

			.content2{position: relative;}
			.title2{font-size: 12px; line-height: 20px;margin-bottom:13px;float: left;}
			.xian{border-bottom: 2px solid #ccc;}
    </style>
</head>
<body>

<div id='header' class="am-g am-topbar-fixed-top" >
	<div  onclick="api.closeWin();"  class="am-u-sm-2" style="margin-top:12px;padding-left: 17px">
		<img  src="images/arr-l.png" style="height:14px;height: 18px;"/>
	</div> 
	<div class="am-u-sm-8 til" style="margin-top:13px;text-align:center;">
		<h1>我的消息</h1>
	</div>
	<div class="am-u-sm-2" style="font-size: 20px;margin-top:10px;color:white;text-align:center;">

   </div>
</div>

<div class="am-g" style="margin-top: 50px" id="list">

    <!--<div class="content">
        <div class="title">2015年12月24日</div>
    </div>
    <div class="content2">
        <div class="title2">系统消息：中国好队友</div>
    </div>
    <div class="xian clear"></div>-->

</div>
	
</body>

<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript">
	var list = [];
	
	apiready = function() {
		readFile();
	};
	
	function readFile() {
		api.readFile({
		    path:'fs://push.txt'
	    },function(ret,err){
	    	alert('data==='+JSON.stringify(ret.data));
	    	if(ret.status){
		        list = ret.data;
		        
		    } else{
		        api.alert({
		            msg: '没有历史推送消息'
		        });
		    }
		    
		    updateUI(list);
	    });
	}
	
	function updateUI(list){
		var dataHtml = '';
		
	    if(list.length > 0){
			for(var i = list.length-1; i >= 0; i--){
				dataHtml += '<div class="content" onclick="handleClick('+ i + ')">';
	    		    dataHtml += '<div class="title">' + list[i].date + '</div>';
	            dataHtml += '</div>';
	            dataHtml += '<div class="content2" onclick="handleClick('+ i + ')">';
	            	dataHtml += '<div class="title2">' + list[i].content + '</div>';
	            dataHtml += '</div>';
	            dataHtml += '<div class="xian clear"></div>';
	       }
	    }else{
	       dataHtml += '<div class="am-u-sm-12" style="margin-top:10px;text-align:center">暂无数据...</div>'
	    }
	    
		$api.html($api.byId('list'), dataHtml);
	}
	
	function handleClick(index){
		var data = list[index];
		var type = data.type;
		var value = data.value;
		var content = data.content;
		
		if('通知'==type){
			handleNotice(content);
		}else if('网页'==type){
			handleWeb(value, content);
		}else if('商品'==type){
			handleProduct(value, content);
		}else if('更新'==type){
			handleUpdate(content);
		}
	}
	
	function handleNotice(notice){
		api.alert({
		    title: '您有一条新的消息',
		    msg: notice,
		    buttons:['知道']
		});
	}
	
	function handleWeb(url, content){
		api.confirm({
		    title: '您有一条新的消息',
		    msg: content,
		    buttons:['看看','忽略']
		},function(ret,err){
		    if(ret.buttonIndex == 1){
		        api.openWin({
					name: 'webpage',
			        url: 'openWebPage.html',
			      	pageParam: {'title':content,'url':url},
			        opaque: true,
			        vScrollBarEnabled:false
			    });
		    }
		});
	}
	
	function handleProduct(id, content){
		api.confirm({
		    title: '您有一条新的消息',
		    msg: content,
		    buttons:['看看','忽略']
		},function(ret,err){
		    if(ret.buttonIndex == 1){
		        //加载商品信息
				do_ajax('/app/productshow?id='+id,'get',{},function(ret,err){
					if(ret){
						//跳转页面
						api.openWin({
						    name: 'productinfo',
						    url: '../shop/productinfo.html',
						    pageParam: {product:ret}
					    });
					}else{
						api.alert({
							msg:('错误码：'+err.code+'；错误信息：'+err.msg+'网络状态码：'+err.statusCode)
				        });
					}
	       			api.hideProgress(); 
				});
		    }
		});
	}
	
	function handleUpdate(content){
		api.confirm({
		    title: '您有一条新的消息',
		    msg: content,
		    buttons:['马上更新','下次再说']
		},function(ret,err){
		    if(ret.buttonIndex == 1){
		    	var url = '';
		    
		    	if(api.systemType == 'android'){
					url = 'http://www.72gs.net/upload/72gs.apk';
				}else{
					url = 'https://itunes.apple.com/us/app/72gong-she/id1021506538?l=zh&ls=1&mt=8'
				}
				
		        api.openWin({
					name: 'webpage',
			        url: 'openWebPage.html',
			      	pageParam: {'title':'版本更新','url':url},
			        opaque: true,
			        vScrollBarEnabled:false
			    });
		    }
		});
	}
		
</script>

</html>
